package controllers

import (
	"gitee.com/ha666/golibs"
	"golang.org/x/net/context"
	"rpc_models"
)

type ToolGetPwdArgs struct {
	Base   BaseRequest
	Length int
}

func (t *BaseRPC) ToolGetPwd(ctx context.Context, args *ToolGetPwdArgs, reply *rpc_models.ToolGetPwdReply) error {
	reply.IsSuccess = false
	errcode, errmsg := args.Base.Verify()
	if errcode > 0 || len(errmsg) > 0 {
		reply.Code = errcode
		reply.Msg = errmsg
		return nil
	}
	if args.Length <= 0 {
		reply.Code = 200002
		reply.Msg = "参数Length错误，不能为空！"
		return nil
	}
	if args.Length > 64 {
		reply.Code = 200003
		reply.Msg = "参数Length错误，不能超过64位！"
		return nil
	}
	reply.IsSuccess = true
	reply.Code = 200000
	reply.Pwd = golibs.GetPwd(args.Length)
	return nil
}
